package logic

import (
	"context"
	"user_srv/models/mysql"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *user.UserListRequest) (*user.UserListResponse, error) {
	// todo: add your logic here and delete this line
	var u mysql.User

	list, err := u.UserList()
	if err != nil {
		return nil, err
	}
	var slice []*user.UserList

	for _, v := range list {
		userList := user.UserList{
			UserId:     int64(v.ID),
			Mobile:     v.Mobile,
			Avatar:     v.Avatar,
			UserStatus: v.UserStatus,
		}
		slice = append(slice, &userList)
	}
	return &user.UserListResponse{
		List: slice,
	}, nil
}
